﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstrumentCheck.Module;
using InstrumentCheck.BLL;

namespace InstrumentCheck.WebAppUI.UserControl
{
    public partial class UCSelectPR : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            List<PR> list = QueryPR_bll.GetQueryInfo_bll(txtTableName.Text.Trim(), txtKeyWord.Text);
            Session["listPR"] = list;
            BindGridView(list);
        }

        private void BindGridView(List<PR> list)
        {
            gvPRInfo.DataSource = list;
            gvPRInfo.DataBind();
            gvPRInfo.Visible = true;

            if (list == null)
            {
                gvPRInfo.Visible = false;
                lblNoData.Text = "沒有找到任何資料！";
            }
            else
            {
                gvPRInfo.Visible = true;
                lblNoData.Text = "";
            }
        }

        protected void gvPRInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            List<PR> list = Session["listPR"] as List<PR>;
            gvPRInfo.PageIndex = e.NewPageIndex;
            BindGridView(list);
        }

        protected void gvPRInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E0E0E0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                e.Row.Attributes["style"] = "Cursor:hand";
                e.Row.Attributes.Add("OnClick", "returnPRValue('" + PublicFunction.Decode(e.Row.Cells[0].Text) + "')");

                PR PRInfo = e.Row.DataItem as PR;
                e.Row.Cells[1].Text = PRInfo.PRApplicant.EmpChineseName;
                e.Row.Cells[2].Text = PRInfo.PRApplicant.DeptNO;

                switch (PRInfo.PRStatus)
                {
                    case FormStatus.Agree:
                        e.Row.Cells[4].Text = "同意";
                        break;
                    case FormStatus.Disagree:
                        e.Row.Cells[4].Text = "不同意";
                        break;
                    case FormStatus.WithDraw:
                        e.Row.Cells[4].Text = "已抽單";
                        break;
                    case FormStatus.Processing:
                        e.Row.Cells[4].Text = "簽核中";
                        break;
                    default:
                        e.Row.Cells[4].Text = "";
                        break;
                }
            }
        }
    }
}